﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace FuncWorks.Xna.UI.Menu
{
    public class IntegerItem : MenuItemWithValue
    {
        public int MinValue { get; set; }
        public int MaxValue { get; set; }
        public int StepValue { get; set; }
        public int Value { get; set; }

        public IntegerItem(string title, TextAlignment alignment, int minValue, int maxValue, int startValue, int step) : base (title, alignment)
        {
            MinValue = minValue;
            MaxValue = maxValue;
            Value = (int)MathHelper.Clamp(startValue, minValue, maxValue);
            StepValue = step;
        }

        public override void Activate() { }

        public override void MoveLeft()
        {
            Value -= StepValue;
            ApplyLimits();
        }

        public override void MoveRight()
        {
            Value += StepValue;
            ApplyLimits();
        }

        protected override void ApplyLimits()
        {
            if (Value < MinValue) { Value = MinValue; }
            if (Value > MaxValue) { Value = MaxValue; }
        }

        protected override string DisplayedValue
        {
			get { return Value.ToString(); }
        }
    }
}
